package com.neuedu.ylbx.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.neuedu.ylbx.pojo.DiagnosisTreatment;
import com.neuedu.ylbx.pojo.DrugInfo;
import com.neuedu.ylbx.pojo.MedicalService;
import com.neuedu.ylbx.service.DiagnosisTreatmentService;
import com.neuedu.ylbx.utils.ResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/drugInfo")
@Tag(name = "诊疗项目医嘱控制器")
@CrossOrigin
public class DiagnosisTreatmentController {
    @Autowired
    private DiagnosisTreatmentService diagnosisTreatmentService;

    @GetMapping("/getDiagnosisTreatment")
    @Operation(summary = "获取诊疗项目列表")
    public ResultVo<List<DiagnosisTreatment>> listTreatmentPage() throws Exception{
        return ResultVo.ok(diagnosisTreatmentService.list());
    }

    @PostMapping("/addDiagnosisTreatment")
    @Operation(summary = "添加诊疗项目")
    public ResultVo addDiagnosisTreatmentPage(DiagnosisTreatment diagnosisTreatment) throws Exception{
        diagnosisTreatmentService.save(diagnosisTreatment);
        return ResultVo.ok("添加成功");
    }

    @RequestMapping("/updateDiagnosisTreatment")
    @Operation(summary = "更新诊疗项目")
    public ResultVo updateDiagnosisTreatment(DiagnosisTreatment diagnosisTreatment) throws Exception {
        UpdateWrapper<DiagnosisTreatment> updateWrapper = new UpdateWrapper<DiagnosisTreatment>();
        updateWrapper.eq("id",diagnosisTreatment.getId());
        diagnosisTreatmentService.update(diagnosisTreatment,updateWrapper);
        return ResultVo.ok("修改成功");
    }

    @RequestMapping("/deleteDiagnosisTreatment")
    @Operation(summary = "删除诊疗项目")
    public ResultVo deleteDiagnosisTreatment(Integer id) throws Exception {
        diagnosisTreatmentService.removeById(id);
        return ResultVo.ok("删除成功");
    }
    @DeleteMapping("/deleteDiagnosisTreatment")
    @Operation(summary = "批量删除药品")
    public ResultVo deleteDiagnosisTreatments(@RequestBody List<Long> Ids){
        diagnosisTreatmentService.removeByIds(Ids);  // MyBatis-Plus 批量删除方法
        return ResultVo.ok("批量删除成功");
    }
}
